<template>
    <section>
        <compFormQuery
            class="margin-layout"
            ref="formbase"
            :formdata="getBase"
            :value="formData"
            :labelWidth="120"
        />
        <div class="text-right padding-right-10 padding-bottom-10">
            <Button @click="close">关闭</Button>
        </div>
        <Spin loading size="large" v-if="loading"></Spin>
    </section>
</template>

<script>
import { mapGetters } from "vuex";
import { HttpTaskCenter } from "../../../service/notice";
export default {
    props: ["id"],
    data() {
        return {
            loading: false,
            formData: {}
        };
    },
    created() {
        this.getDetail();
    },
    computed: {
        ...mapGetters("dictionary", ["getProductList"]),
        getBase() {
            return [
                {
                    label: "任务编号：",
                    key: "taskNo"
                },
                {
                    label: "处理状态：",
                    key: "status"
                },
                {
                    label: "任务开始时间：",
                    key: "createdAt"
                },
                {
                    label: "任务结束时间：",
                    key: "updatedAt"
                },
                {
                    label: "创建人：",
                    key: "createdName"
                },
                {
                    label: "关联单据号：",
                    key: "sourceNo"
                },
                {
                    label: "项目：",
                    key: "lineId",
                    valueText: this.findRenderLabel(
                        this.getProductList,
                        this.formData.lineId
                    )
                },
                {
                    label: "任务描述：",
                    key: "taskTitle"
                },
                {
                    label: "异常信息：",
                    key: "errorMsg"
                },
                {
                    label: "相关文件：",
                    key: "taskFile",
                    valueText:
                        this.formData.taskFile &&
                        `<a href="${this.formData.taskFile}" download class="color-link">下载文件</a>`
                },
                {
                    label: "其他参数：",
                    key: "otherParameter"
                },
                {
                    label: "备注：",
                    key: "remark"
                }
            ];
        }
    },
    methods: {
        close() {
            this.$emit("on-close");
        },
        async getDetail() {
            this.loading = true;
            HttpTaskCenter({
                id: this.id
            }).then(
                res => {
                    this.formData = res.data;
                    this.loading = false;
                    if (
                        (this.formData.errorDetail || "").indexOf("==>") != -1
                    ) {
                        this.formData.errorMsg = "调用对应业务逻辑时发生异常";
                    }
                },
                err => {
                    this.$Message.error(err.message);
                    this.loading = false;
                }
            );
        }
    }
};
</script>
